#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"

#define DEBUG 0
#define NOISY_TEST 1


int main () {
    int k[10] = {adventurer, council_room, feast, gardens, mine,
	       remodel, smithy, village, baron, great_hall};
    int player1 = 0;
    int handCount = 5;
    int count, i;
    int coppers[MAX_HAND];
    for (i = 0; i < MAX_HAND; i++) {
        coppers[i] = copper;
    }
    struct gameState G;

    printf ("Testing gainCard.\n");

#if (NOISY_TEST == 1)
    printf("Testing gainCard: add to discard.\n");
#endif

    initializeGame(2, k, 1, &G);
    G.handCount[player1] = handCount;
    memcpy(G.hand[player1], coppers, sizeof(int) * handCount); // set all the cards to copper

    count = G.supplyCount[adventurer]; //find out how many adventurer cards there are in the stack
    assert(gainCard(adventurer, &G, 0, player1) == 0); // draw an adventurer card
    assert(G.supplyCount[adventurer] == (count - 1)); // ensure our adventurer supply went down
    assert(G.discard[player1][G.discardCount[player1] - 1] == adventurer); // ensure we actually got an adventurer card 

#if (NOISY_TEST == 1)
    printf("Test passed.\n");
#endif


#if (NOISY_TEST == 1)
    printf("Testing gainCard: add to deck.\n");
#endif

    initializeGame(2, k, 1, &G);
    G.handCount[player1] = handCount;
    memcpy(G.hand[player1], coppers, sizeof(int) * handCount); // set all the cards to copper

    count = G.supplyCount[adventurer]; //find out how many adventurer cards there are in the stack
    assert(gainCard(adventurer, &G, 1, player1) == 0); // draw an adventurer card
    assert(G.supplyCount[adventurer] == (count - 1)); // ensure our adventurer supply went down
    assert(G.deck[player1][G.deckCount[player1] - 1] == adventurer); // ensure we actually got an adventurer card 

#if (NOISY_TEST == 1)
    printf("Test passed.\n");
#endif


#if (NOISY_TEST == 1)
    printf("Testing gainCard: add to hand.\n");
#endif

    //reset gamestate
    initializeGame(2, k, 1, &G);
    G.handCount[player1] = handCount;
    memcpy(G.hand[player1], coppers, sizeof(int) * handCount); // set all the cards to copper

    count = G.supplyCount[adventurer]; //find out how many adventurer cards there are in the stack
    assert(gainCard(adventurer, &G, 2, player1) == 0); // draw an adventurer card
    assert(G.supplyCount[adventurer] == (count - 1)); // ensure our adventurer supply went down
    assert(G.hand[player1][G.handCount[player1] - 1] == adventurer); // ensure we actually got an adventurer card 

#if (NOISY_TEST == 1)
    printf("Test passed.\n");
#endif

    printf("gainCard(): All tests passed!\n");

    return 0;
}
